# ~*~ coding: utf-8 ~*~
from wtforms.validators import Regexp


class Phone(Regexp):
    """手机号码"""

    def __init__(self, message):
        super().__init__('^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$',
                         flags=0, message=message)


class Email(Regexp):

    def __init__(self, message):
        super().__init__('^[a-z0-9._%-]+@([a-z0-9-]+\.)+[a-z]{2,4}$', flags=0, message=message)


class Domain(Regexp):
    """域名"""

    def __init__(self, message):
        super().__init__('[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(/.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+/.?', flags=0, message=message)


class IPAddress(Regexp):
    """IP地址"""

    def __init__(self, message):
        super().__init__('^(((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?))?$', flags=0, message=message)


class Account(Regexp):
    """帐号是否合法(字母开头，允许5-16字节，允许字母数字下划线)"""

    def __init__(self, message):
        super().__init__('^[a-zA-Z][a-zA-Z0-9_]{4,15}$', flags=0, message=message)


class Password(Regexp):
    """密码(以字母开头，长度在6~18之间，只能包含字母、数字和下划线)"""

    def __init__(self, message):
        super().__init__('^[a-zA-Z]\w{5,17}$', flags=0, message=message)


class Date(Regexp):
    """日期"""

    def __init__(self, message):
        super().__init__('^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])', flags=0, message=message)


class Time(Regexp):

    def __init__(self, message):
        super().__init__('^(20|21|22|23|[0-1]\d):[0-5]\d:[0-5]\d', flags=0, message=message)


class DateTime(Regexp):
    """日期时间"""

    def __init__(self, message):
        super().__init__('^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])'
                         '\s+'
                         '(20|21|22|23|[0-1]\d):[0-5]\d:[0-5]\d$',
                         flags=0, message=message)


class Number(Regexp):
    """数字"""

    def __init__(self, message):
        super().__init__('^[0-9]*$', flags=0, message=message)


class Float(Regexp):
    """浮点数"""

    def __init__(self, message):
        super().__init__('^(-?\d+)(\.\d+)?$', flags=0, message=message)


class Chinese(Regexp):

    def __init__(self, message):
        super().__init__('^[\u4E00-\u9FA5]+$', flags=0, message=message)
